package cn.com.smartdevices.bracelet.chart;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;

import com.goodving.guli.R;
import com.goodving.guli.bt.profile.scale.HeartRateInfo;
import com.goodving.guli.view.C4220a;

import cn.com.smartdevices.bracelet.chart.base.PieChart;
import cn.com.smartdevices.bracelet.chart.util.AnimUtil;
import cn.com.smartdevices.bracelet.chart.util.C0804t;
import cn.com.smartdevices.bracelet.chart.util.ChartData;

/* renamed from: cn.com.smartdevices.bracelet.chart.o */
public class DynamicPieChart extends PieChart {
    private static final String f4008g = "Chart.DynamicPieChart";
    private static final float f4009h = 1.33f;
    private static final float f4010i = 14.33f;
    private static final float f4011x = 16.33f;
    private static final int f4012y = 200;
    private int f4013A;
    private Bitmap f4014B;
    private Bitmap f4015C;
    private Bitmap f4016D;
    private Paint f4017E;
    private Paint f4018F;
    private float f4019G;
    private Paint f4020H;
    private RectF f4021I;
    private RectF f4022J;
    private float f4023K;
    private float[] f4024L;
    private boolean f4025z;

    public DynamicPieChart(Context context) {
        super(context);
        this.f4014B = ((BitmapDrawable) context.getResources().getDrawable(R.drawable.ic_dynamic_step)).getBitmap();
        this.f4015C = ((BitmapDrawable) context.getResources().getDrawable(R.drawable.ic_dynamic_sleep)).getBitmap();
        this.f4016D = ((BitmapDrawable) context.getResources().getDrawable(R.drawable.heart_icon)).getBitmap();
        this.f4017E = new Paint(1);
        this.f4018F = new Paint(1);
        this.f4017E.setColor(-1);
        this.f4017E.setStrokeWidth(this.mDensity * f4009h);
        this.f4017E.setStyle(Style.STROKE);
        this.f4018F.setColor(1308622847);
        this.f4018F.setStrokeWidth(this.mDensity * f4009h);
        this.f4018F.setStyle(Style.STROKE);
        this.f4023K = f4010i * this.mDensity;
        this.f4019G = f4011x * this.mDensity;
        this.f4020H = new Paint(1);
        this.f4020H.setColor(1308622847);
        this.f4020H.setStrokeWidth(1.0f);
        this.f4020H.setStyle(Style.STROKE);
    }

    private void m8701a(float f, float f2, float f3, Canvas canvas) {
        float f4 = 0.0f;
        if (this.f4013A > 0) {
            f4 = 7.0f;
        }
        canvas.drawArc(this.f4021I, f4 - 90.0f, 360.0f - (f4 * 2.0f), false, this.f4020H);
        m8702a(canvas, f, f2, f3, this.f4018F, f4012y);
    }

    private void m8702a(Canvas canvas, float f, float f2, float f3, Paint paint, int i) {
        if (this.f4024L == null) {
            this.f4024L = new float[AnimUtil.f4064d];
            float strokeWidth = (f3 - (this.f4020H.getStrokeWidth() / 2.0f)) - (this.f4019G * 2.0f);
            float strokeWidth2 = ((f3 - (this.f4020H.getStrokeWidth() / 2.0f)) - (this.f4019G * 2.0f)) - this.f4023K;
            for (int i2 = 0; i2 < f4012y; i2++) {
                float f4 = ((float) i2) * 0.03141593f;
                float sin = (float) (((double) f) + (Math.sin((double) f4) * ((double) strokeWidth)));
                float cos = (float) (((double) f2) - (Math.cos((double) f4) * ((double) strokeWidth)));
                float sin2 = (float) (((double) f) + (Math.sin((double) f4) * ((double) strokeWidth2)));
                f4 = (float) (((double) f2) - (Math.cos((double) f4) * ((double) strokeWidth2)));
                this.f4024L[i2 * 4] = sin;
                this.f4024L[(i2 * 4) + 1] = cos;
                this.f4024L[(i2 * 4) + 2] = sin2;
                this.f4024L[(i2 * 4) + 3] = f4;
            }
        }
        canvas.drawLines(this.f4024L, 0, i * 4, paint);
    }

    public void m8703a() {
        this.f4025z = true;
    }

    public void m8704a(int i) {
        this.f4013A = i;
        switch (this.f4013A) {
            case 1 /*1*/:
                this.f4020H.setColor(1728053247);
            case C4220a.bp /*16*/:
                this.f4020H.setColor(1308622847);
            default:
        }
    }

    protected void drawPie(Canvas canvas, RectF rectF, float f, float f2, float f3, float f4, float f5) {
        m8701a(f, f2, f3, canvas);
        float f6 = this.mDensityScale;
        if (C0804t.m8835a()) {
            f6 = (float) (((double) f6) * 0.88d);
        }
        switch (this.f4013A) {
            case 1 /*1*/:
                C0804t.m8830a(canvas, this.f4022J.centerX(), this.f4022J.centerY(), f6, this.f4014B, null);
                break;
            case C4220a.bp /*16*/:
                C0804t.m8830a(canvas, this.f4022J.centerX(), this.f4022J.centerY(), f6, this.f4015C, null);
                break;
            case ChartData.f4049d /*4096*/:
                if (this.f3986f > 0.0f) {
                    this.f4017E.setAlpha((int) this.f3986f);
                } else {
                    this.f4017E.setAlpha(HeartRateInfo.HR_EMPTY_VALUE);
                }
                C0804t.m8830a(canvas, this.f4022J.centerX(), this.f4022J.centerY(), f6, this.f4016D, null);
                break;
        }
        float f7 = f4 * f5;
        if (f7 > 1.0f) {
            f7 = 1.0f;
        }
        Canvas canvas2;
        float f8;
        float f9;
        if (this.f4025z) {
            canvas.save();
            canvas.rotate(this.mRotate * 360.0f, f, f2);
            if (f7 < 0.3f) {
                f7 = 0.3f;
            }
            if (f7 > 0.6f) {
                f7 = 0.6f;
            }
            canvas2 = canvas;
            f8 = f;
            f6 = f2;
            f9 = f3;
            m8702a(canvas2, f8, f6, f9, this.f4017E, (int) (f7 * 200.0f));
            canvas.restore();
        } else if (f7 > 0.0f || f7 < 1.0f) {
            canvas2 = canvas;
            f8 = f;
            f6 = f2;
            f9 = f3;
            m8702a(canvas2, f8, f6, f9, this.f4017E, (int) (f7 * 200.0f));
        } else if (f7 == 1.0f) {
            m8702a(canvas, f, f2, f3, this.f4017E, f4012y);
        }
    }

    protected void onRectChanged(RectF rectF) { // m8706a
        super.onRectChanged(rectF);
        this.f4022J = new RectF();
        this.f4022J.left = rectF.centerX() - (15.5f * this.mDensity);
        this.f4022J.top = rectF.top + (2.0f * this.mDensity);
        this.f4022J.right = this.f4022J.left + (this.mDensity * 31.0f);
        this.f4022J.bottom = this.f4022J.top + (this.mDensity * 31.0f);
        this.f4021I = new RectF(rectF);
        RectF rectF2 = this.f4021I;
        rectF2.left += this.f4019G;
        rectF2 = this.f4021I;
        rectF2.top += this.f4019G;
        rectF2 = this.f4021I;
        rectF2.right -= this.f4019G;
        rectF2 = this.f4021I;
        rectF2.bottom -= this.f4019G;
    }

    public void m8707b() {
        this.f4025z = false;
    }
}
